//
//  JiesuanListController.m
//  Ten
//
//  Created by anfuer on 2018/11/17.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "JiesuanListController.h"
#import "JiesuanListCell.h"
#import "SPPageMenu.h"

@interface JiesuanListController ()<SPPageMenuDelegate, UIScrollViewDelegate>
{
    NSMutableArray*mary1;
    NSMutableArray*mary2;
}
@property (weak, nonatomic) IBOutlet UIView *muneBack;
@property (weak, nonatomic) IBOutlet UIScrollView *scrview;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrW;
@property (weak, nonatomic) IBOutlet UITableView *tbv1;
@property (weak, nonatomic) IBOutlet UITableView *tbv2;
@property (weak, nonatomic) IBOutlet UIView *hidenView1;
@property (weak, nonatomic) IBOutlet UIView *hidenView2;
@property (nonatomic, weak) SPPageMenu *pageMenu;
@end

@implementation JiesuanListController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tbv1.separatorColor=[UIColor clearColor];
    _tbv2.separatorColor=[UIColor clearColor];
     _scrW.constant=DEVW*2;
    SPPageMenu *pageMenu = [SPPageMenu pageMenuWithFrame:CGRectMake(0, 0, DEVW, 40) trackerStyle:SPPageMenuTrackerStyleLineAttachment];
    // 传递数组，默认选中第2个
    [pageMenu setItems:@[@"职位",@"公司"] selectedItemIndex:0];
    pageMenu.permutationWay=SPPageMenuPermutationWayNotScrollEqualWidths;
    // 设置代理
    pageMenu.delegate = self;
    [_muneBack addSubview:pageMenu];
    _pageMenu = pageMenu;
    
    
    _tbv1.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
     
        mary1=[NSMutableArray array];
        [self loadData];
    }];
    _tbv2.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
       
        mary2=[NSMutableArray array];
        [self loadData];
    }];
    // Do any additional setup after loading the view.
}
-(void)loadData{
    [_tbv1.mj_header endRefreshing];
    [_tbv2.mj_header endRefreshing];
}
- (IBAction)back:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - scrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView==_scrview) {
        [self.pageMenu moveTrackerFollowScrollView:scrollView];
    }
    
}

- (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
    if (labs(toIndex - fromIndex) >= 2) {
        [_scrview setContentOffset:CGPointMake(DEVW * toIndex, 0) animated:NO];
    } else {
        [_scrview setContentOffset:CGPointMake(DEVW * toIndex, 0) animated:YES];
    }

    mary1=[NSMutableArray array];
    mary2=[NSMutableArray array];
    [self loadData];
}
#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    JiesuanListCell*cell=[JiesuanListCell CellWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}


#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  [JiesuanListCell FSCellHeightForTableView:tableView indexPath:indexPath cacheKey:@"JiesuanListCell" cellContentViewWidth:0 bottomOffset:0];;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [MyUtils collviewSelidex:@"结算详情" toVc:self andShopInfo:nil];
}



@end
